package app.ui;

import java.awt.Color;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;

import app.action.MP3PlayerAction;
import app.action.MouseAction;

public class MP3PlayerUi extends AbsCommonPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1555019135964521111L;

	private JButton[] jButtons;
	private String[] btnTexts = { "Play", "Stop", "Browse.." };
	private JLabel jLabel;
	private JButton closeBtn;

	private MP3PlayerAction mp3PlayerAction;

	public MP3PlayerUi(MainFrame mFrame) {
		super(mFrame);
		setBackground(new Color(100, 255, 100));

		MouseAction mouseAction = new MouseAction(this);
		addMouseMotionListener(mouseAction);
		addMouseListener(mouseAction);
	}

	@Override
	protected void addComponents() {
		this.mp3PlayerAction = new MP3PlayerAction(this);
		this.jButtons = new JButton[btnTexts.length];
		for (int i = 0; i < btnTexts.length; i++) {
			jButtons[i] = new JButton(btnTexts[i]);
			jButtons[i].addActionListener(mp3PlayerAction);
			add(jButtons[i]);
		}

		this.closeBtn = new JButton("X");
		this.closeBtn.addActionListener(mp3PlayerAction);
		add(closeBtn);

		jLabel = new JLabel();
		add(jLabel);
	}

	@Override
	protected void initializeComponents() {
		jLabel.setOpaque(true);
		jLabel.setBackground(new Color(50, 100, 200));

		jButtons[0].setEnabled(false);
		jButtons[1].setEnabled(false);

		jButtons[0].setIcon(new ImageIcon(getClass().getResource("/Icons/play.png")));
		jButtons[1].setIcon(new ImageIcon(getClass().getResource("/Icons/stop.png")));
	}

	@Override
	protected void resizeComponents() {
		int x = 0, y = 0, height = btnHei, width = getWidth();

		// display location of file
		y = (getHeight() - height) / 2 - 4;
		jLabel.setBounds(x, y, width, height);

		// play button
		y += height + 4;
		width = btnWid;
		jButtons[0].setBounds(x, y, width, height);

		// stop button
		x += width;
		jButtons[1].setBounds(x, y, width, height);

		// browse button
		x = getWidth() - width;
		jButtons[2].setBounds(x, y, width, height);

		// close button
		width = 42;
		height = width * 3 / 4;
		x = getWidth() - width - 1;
		y = 1;
		closeBtn.setBounds(x, y, width, height);
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public JButton[] getjButtons() {
		return jButtons;
	}

	public String[] getBtnTexts() {
		return btnTexts;
	}

	public JLabel getjLabel() {
		return jLabel;
	}

	public MP3PlayerAction getMp3PlayerAction() {
		return mp3PlayerAction;
	}

	public JButton getCloseBtn() {
		return closeBtn;
	}

}
